package com.wz;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: WZ
 * @create: 2018-07-20 10:45
 **/
@RestController
public class ComputeController {

    @Autowired
    DiscoveryClient discoveryClient;

    @RequestMapping("/add")
    public Integer add(@RequestParam Integer a, @RequestParam Integer b){

        List<ServiceInstance> list = discoveryClient.getInstances("STORES");
        System.out.println( "discoveryClient.getServices().size() = "+discoveryClient.getServices().size());
        for (String s : discoveryClient.getServices()) {
            System.out.println("service: " + s);
            List<ServiceInstance> serviceInstances = discoveryClient.getInstances("s");
            System.out.println("serviceInstances.size():"+serviceInstances.size());
            for (ServiceInstance si: serviceInstances) {
                System.out.println(" service:" + s + ",getHost()="+si.getHost());
                System.out.println(" service:" + s + ",getServiceId()="+si.getServiceId());
                System.out.println(" service:" + s + ",si.getPort()"+si.getPort());
                System.out.println(" service " + s + ",getUri()"+si.getUri());
            }
        }
        Integer  n = a + b;
        System.out.println("sum:" + n);
        return n;
    }

}
